// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.core.utils;

import java.util.ArrayList;

public final class DirectBufferAllocator {
    private static final Object LOCK = "DirectBufferAllocator.LOCK";
    private static final ArrayList<WrappedBuffer> ALL = new ArrayList();

    public static WrappedBuffer allocate(int size) {
        synchronized (LOCK) {
            destroyDisposed();
            WrappedBuffer wrappedBuffer = new WrappedBuffer(size);
            ALL.add(wrappedBuffer);
            return wrappedBuffer;
        }
    }

    private static void destroyDisposed() {
        synchronized (LOCK) {
            for (int _int = ALL.size() - 1; _int >= 0; _int--) {
                WrappedBuffer wrappedBuffer = (WrappedBuffer)ALL.get(_int);
                if (wrappedBuffer.isDisposed()) {
                    ALL.remove(_int);
                }
            }
        }
    }

    public static long getBytesAllocated() {
        synchronized (LOCK) {
            destroyDisposed();
            long _long = 0L;

            for (int _int = 0; _int < ALL.size(); _int++) {
                WrappedBuffer wrappedBuffer = (WrappedBuffer)ALL.get(_int);
                if (!wrappedBuffer.isDisposed()) {
                    _long += (long)wrappedBuffer.capacity();
                }
            }

            return _long;
        }
    }
}
